import Router from '@koa/router';
import DictionaryController from '@/controllers/DictionaryController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/dictionaries',
});

/**
 * 字典类型路由
 */
router.get('/types', auth, requirePermission('dictionary', PermissionAction.READ), DictionaryController.getTypes.bind(DictionaryController));

router.get('/types/:id', auth, requirePermission('dictionary', PermissionAction.READ), DictionaryController.getTypeDetail.bind(DictionaryController));

router.post('/types', auth, requirePermission('dictionary', PermissionAction.CREATE), DictionaryController.createType.bind(DictionaryController));

router.put('/types/:id', auth, requirePermission('dictionary', PermissionAction.UPDATE), DictionaryController.updateType.bind(DictionaryController));

router.delete('/types/:id', auth, requirePermission('dictionary', PermissionAction.DELETE), DictionaryController.deleteType.bind(DictionaryController));

/**
 * 字典项路由
 */
router.get('/items', auth, requirePermission('dictionary', PermissionAction.READ), DictionaryController.getItems.bind(DictionaryController));

router.post('/items', auth, requirePermission('dictionary', PermissionAction.CREATE), DictionaryController.createItem.bind(DictionaryController));

router.put('/items/:id', auth, requirePermission('dictionary', PermissionAction.UPDATE), DictionaryController.updateItem.bind(DictionaryController));

router.delete('/items/:id', auth, requirePermission('dictionary', PermissionAction.DELETE), DictionaryController.deleteItem.bind(DictionaryController));

/**
 * 公开接口：根据编码获取字典项
 */
router.get('/code/:code', auth, DictionaryController.getItemsByCode.bind(DictionaryController));

export default router;

